package net.zjitc.servlet;

import net.zjitc.po.User;
import net.zjitc.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by guo on 2018/1/3.
 */
@WebServlet(name = "LoginServlet",urlPatterns = "/loginServlet")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        UserService service=new UserService();
        User user = service.findUsernameAndPassword(username, password);
        if(user.getPassword().equals(password)&&user.getUsername().equals(username))
        {
            request.getRequestDispatcher("/success.jsp").forward(request,response);
        }
        else
        {
            request.getRequestDispatcher("/fail.jsp").forward(request,response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
